package com.linxianqin.springbootVue.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linxianqin.springbootVue.domain.convert.SysNoticeConvert;
import com.linxianqin.springbootVue.domain.convert.SysRoleConvert;
import com.linxianqin.springbootVue.domain.dto.SysNoticeDTO;
import com.linxianqin.springbootVue.domain.entity.SysNotice;
import com.linxianqin.springbootVue.domain.entity.SysRole;
import com.linxianqin.springbootVue.domain.query.SysNoticeQuery;
import com.linxianqin.springbootVue.mapper.SysNoticeMapper;
import com.linxianqin.springbootVue.service.SysNoticeService;
import com.linxianqin.springbootVue.utils.DateUtils;
import com.linxianqin.springbootVue.utils.text.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 通知公告表 服务实现类
 * </p>
 *
 * @author lxq
 * @since 2020-12-28
 */
@Service
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements SysNoticeService {


    /**
     * 根据条件分页查询数据
     * @param page  分页条件
     * @param query  信息
     * @return 数据集合信息
     */
    @Override
    public Page<SysNoticeDTO> selectRolePage(Page<SysNoticeDTO> page, SysNoticeQuery query) {
        Page<SysNotice> entityPage = SysNoticeConvert.INSTANCE.dto2entity(page);
        LambdaQueryWrapper<SysNotice> queryWrapper=new QueryWrapper<SysNotice>().lambda();
        if (StringUtils.isNotNull(query.getNoticeTitle())){
            queryWrapper.like(SysNotice::getNoticeTitle,query.getNoticeTitle());
        }
        if (StringUtils.isNotNull(query.getCreateBy())){
            queryWrapper.like(SysNotice::getCreateBy,query.getCreateBy());
        }
        if (StringUtils.isNotNull(query.getNoticeType())){
            queryWrapper.eq(SysNotice::getNoticeType,query.getNoticeType());
        }
        Page<SysNotice> selectPage = baseMapper.selectPage(entityPage, queryWrapper);
        return SysNoticeConvert.INSTANCE.entity2dto(selectPage);
    }
}
